package com.woniu.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.woniu.apartment.domain.Country;
import com.woniu.apartment.service.ICountryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 国家列Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbcountry")
@Api("国家列管理")
public class CountryController extends BaseController
{
    @Autowired
    private ICountryService countryService;

    /**
     * 查询国家列列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcountry:list')")
    @GetMapping("/list")
    @ApiOperation("国家列分页查询")
    public TableDataInfo list(Country country)
    {
        startPage();
        List<Country> list = countryService.selectCountryList(country);
        return getDataTable(list);
    }

    /**
     * 导出国家列列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcountry:export')")
    @Log(title = "国家列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("国家列导出")
    public void export(HttpServletResponse response, Country country)
    {
        List<Country> list = countryService.selectCountryList(country);
        ExcelUtil<Country> util = new ExcelUtil<Country>(Country.class);
        util.exportExcel(response, list, "国家列数据");
    }

    /**
     * 获取国家列详细信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcountry:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据主键查询国家列")
    @ApiImplicitParam(name = "ids", value = "用户ID", required = true, dataType = "Long")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(countryService.selectCountryById(id));
    }

    /**
     * 新增国家列
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcountry:add')")
    @Log(title = "国家列", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加国家列")
    public AjaxResult add(@RequestBody Country country)
    {
        return toAjax(countryService.insertCountry(country));
    }

    /**
     * 修改国家列
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcountry:edit')")
    @Log(title = "国家列", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新国家列")
    public AjaxResult edit(@RequestBody Country country)
    {
        return toAjax(countryService.updateCountry(country));
    }

    /**
     * 删除国家列
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcountry:remove')")
    @Log(title = "国家列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除国家列")
    @ApiImplicitParam(name = "ids", value = "主键数组", required = true, dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(countryService.deleteCountryByIds(ids));
    }
}
